package pers.aidenj.ostrich.controller.swagger;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import io.swagger.annotations.ApiOperation;
import pers.aidenj.ostrich.model.UserLog;
import pers.aidenj.ostrich.service.druidDemo.DruidDemoService;

@Controller
@RequestMapping("ehcache")
public class SwaggerEhcacheDemo {
	
	@Autowired
	DruidDemoService druidDemoService;
	
	@ApiOperation(value = "存入ehcache", notes = "数据存入ehcache", httpMethod = "GET")
    @RequestMapping(value="getDemo01", method= RequestMethod.GET)
	@ResponseBody
	public JSONObject getDemo01(String str){
		JSONObject jo = new JSONObject();
		jo.put("Dictionary",str);
		return jo;
	}

	@ApiOperation(value = "读取ehcache", notes = "读取ehcache数据", httpMethod = "GET")
    @RequestMapping(value="getDemo02", method= RequestMethod.GET)
	@ResponseBody
	public JSONObject getDemo02(String str){
		UserLog userLog = new UserLog();
		
		for (int i = 0; i < 1000; i++) {
			userLog.setUserId(i+1);
			userLog.setLandingTime(new Date());
			userLog.setLoginIp("127.0.0.1");
			userLog.setLoginAddress("测试"+i);
			druidDemoService.save(userLog);
		}
		return null;
	}

}
